<template>
  <h1>循环指令</h1>
  <ul v-for="i in 5">
    <li>hello-world</li>
    <li>hello-world</li>
    <li>hello-world</li>
  </ul>
  <ul>
    <li v-for="item in 5">{{'hello'+item}}</li>
  </ul>
  <ul>
    <li v-for="pre in productArr">{{pre}}</li>
  </ul>
  <table border="1">
    <tr>
      <th>商品编号</th>
      <th>商品名称</th>
      <th>商品价格</th>
      <th>商品库存</th>
      <th>操作</th>
    </tr>
    <tr v-for="(item,index) in productArr">
      <td>{{index+1}}</td>
      <td>{{item.title}}</td>
      <td>{{item.price}}</td>
      <td>{{item.num}}</td>
      <td><button @click="del(index)">删除</button></td>
    </tr>
  </table>

</template>
<script setup>
import {ref} from "vue";
const productArr = ref([
  {title:"小米手机",price:1999,num:10},
  {title:"华为手机",price:2999,num:12},
  {title:"苹果手机",price:3999,num:34},
  {title:"三星手机",price:4999,num:133},
  {title:"oppo手机",price:5999,num:155},
])
const del = (index)=>{
  if (confirm("你确认删除吗？")){
    productArr.value.splice(index,1)
  }
}
</script>
<style scoped>
</style>